package com.michael.demos.springboot.mybatisplus.customizedId.util;

import cn.hutool.core.lang.Snowflake;
import com.michael.demos.springboot.mybatisplus.customizedId.core.IdMaker;

import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * ID,订单号生成器工具类
 */
public class NumUtil implements Serializable {

    private static final long serialVersionUID = 1L;

    /** 起始的时间戳 2021-5-20 13:14:00 */
    private static final long START_POINT_MS = 1624166040000L;
    private static final Date START_POINT = new GregorianCalendar(2021, Calendar.JUNE, 20, 13, 14, 0).getTime();

    public static IdMaker initIdMaker(long workerId, long dataCenterId, boolean isUseSystemClock) {
        return new IdMaker(workerId, dataCenterId, isUseSystemClock);
    }

    public static void main(String[] args) {

    }

    public static LocalDateTime getDateTime(long time) {
        //通过时间毫秒数创建Instant实例
        Instant instant = Instant.ofEpochMilli(time);
        //通过系统默认时区创建ZonedDateTime
        ZonedDateTime zonedDateTime = instant.atZone(ZoneId.systemDefault());
        //从ZonedDateTime中获取LocalDateTime部分
        return zonedDateTime.toLocalDateTime();
    }

}
